package com.itheima.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.item.mapper.GoodsMapper;
import com.itheima.item.pojo.GoodInfo;
import com.itheima.item.service.GoodService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class GoodServiceImpl extends ServiceImpl<GoodsMapper,GoodInfo> implements GoodService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public GoodInfo findGoodsById(Long id) {
        return goodsMapper.findGoodsById(id);
    }


    @Override
    public List<GoodInfo> findByPage(Integer pageNum, Integer pageSize) {
        return goodsMapper.findByPage(pageNum,pageSize);
    }

    @Override
    public Boolean deleteAndSendMsg(Long id) {
        this.removeById(id);
        rabbitTemplate.convertAndSend("updateNeeded","updateMsg",id);
        return true;
    }

    @Override
    public Boolean addOrUpdate(GoodInfo goodInfo) {
        this.saveOrUpdate(goodInfo);
        rabbitTemplate.convertAndSend("updateNeeded","updateMsg",goodInfo.getId());
        return true;
    }
}